package domain

import (
	jsoniter "github.com/json-iterator/go"
)

type Result struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

type Cmd struct {
	Cmd    string         `json:"cmd"`
	Params map[string]any `json:"params"`
}

func Success(data any) string {
	res := &Result{
		Code:    "0",
		Message: "success",
		Data:    data,
	}

	bs, _ := jsoniter.Marshal(res)

	return string(bs)
}

func IlegalCmd(cmd string) string {
	res := &Result{
		Code:    "1",
		Message: "ilegal cmd:" + cmd,
	}

	bs, _ := jsoniter.Marshal(res)

	return string(bs)
}

func UnmarshalCmdFailed() string {
	res := &Result{
		Code:    "1",
		Message: "unmarshal cmd:",
	}

	bs, _ := jsoniter.Marshal(res)

	return string(bs)
}
